package com.glc.hms.system.controller.web;

import com.glc.hms.common.controller.BaseController;
import com.glc.hms.common.data.ResponseData;
import com.glc.hms.common.data.SuccessResponseData;
import com.glc.hms.core.annotation.SysLogAnno;
import com.glc.hms.system.entity.SysDept;
import com.glc.hms.system.model.param.AddDeptParam;
import com.glc.hms.system.model.vo.DeptTreeVO;
import com.glc.hms.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Santa
 * @since 2019/12/3
 */
@Slf4j
@Api(value = "部门", description = "部门接口", basePath = "/webApi/dept")
@RestController
@RequestMapping("/webApi/dept")
public class DeptController extends BaseController {

    @Autowired
    private ISysDeptService deptService;

    @ApiOperation(value = "部门列表", response = ResponseData.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseData getList(){
        List<DeptTreeVO> deptTreeVOS = deptService.queryDeptByUserDeptId();
        return new SuccessResponseData(deptTreeVOS);
    }

    @ApiOperation(value = "添加部门", response = ResponseData.class)
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SysLogAnno(value = "添加部门")
    public ResponseData add(@RequestBody AddDeptParam addDeptParam){
        deptService.addDept(addDeptParam);
        return SUCCESS_TIP;
    }

    @ApiOperation(value = "删除部门", response = ResponseData.class)
    @RequestMapping(value = "/del", method = RequestMethod.GET)
    @SysLogAnno(value = "删除部门")
    public ResponseData del(@ApiParam(name = "deptId", value = "组织id", required = true) Long deptId){
        deptService.delDept(deptId);
        return SUCCESS_TIP;
    }

    @ApiOperation(value = "修改部门", response = ResponseData.class)
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @SysLogAnno(value = "修改部门")
    public ResponseData update(@RequestBody SysDept param){
        deptService.updateDept(param);
        return SUCCESS_TIP;
    }
}























